package org.gd.hellojaxb.privat24.other;

import org.gd.hellojaxb.adapters.DateAdaptersFactory;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Date;

/**
 * @author User
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "date")
public class SessionCounterDate {

    @XmlAttribute(name = "startDate", required = true)
    @XmlJavaTypeAdapter(DateAdaptersFactory.DateTimeFormat.class)
    private Date startDate;

    @XmlAttribute(name = "endDate", required = true)
    @XmlJavaTypeAdapter(DateAdaptersFactory.DateTimeFormat.class)
    private Date endDate;

    @XmlAttribute(name = "difference", required = true)
    @XmlJavaTypeAdapter(DateAdaptersFactory.SessionFormat.class)
    private Date difference;

    public SessionCounterDate() {
        setStartDate(new Date());
        setEndDate(new Date());
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
        setDifference(new Date(this.endDate.getTime() - this.startDate.getTime()));
    }

    public Date getDifference() {
        return difference;
    }

    private void setDifference(Date difference) {
        this.difference = difference;
    }
}